package com.java.comprehensive.arithmetic.leecode.easy;

import java.util.Arrays;

/**
 * @Author: 窦绍飞
 * @Date: 2022/8/8
 */
public class LeetCode_977 {

	public int[] sortedSquares(int[] nums) {
		int l = 0;
		int r = nums.length - 1;
		int[] result = new int[nums.length];
		int count = result.length - 1;
		while (l <= r) {
			if (Math.abs(nums[l]) > Math.abs(nums[r])) {
				result[count] = (int) Math.pow(Math.abs(nums[l]), 2);
				l++;
			} else {
				result[count] = (int) Math.pow(Math.abs(nums[r]), 2);
				;
				r--;
			}
			count--;
		}
		return result;
	}

	public static void main(String[] args) {
		int[] nums = {-7, -3, 2, 3, 11};
		LeetCode_977 leetCode_977 = new LeetCode_977();
		int[] ints = leetCode_977.sortedSquares(nums);
		System.out.println(Arrays.toString(ints));
	}
}
